var a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), e = require("../../../mycomponent/payKeyboard/PayKeyboardAsync.js"), n = getApp(), r = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ r ],
    data: {
        integral: "积分",
        credit1: "0.00",
        transfer_id: "",
        memberInfo: "",
        info_form: {
            transfer_id: "",
            transfer_point: ""
        },
        payKeyboardShow: !1,
        need_password: !1,
        has_password: !1,
        remark: ""
    },
    onLoad: function(a) {
        try {
            var t = wx.getStorageSync("integral");
            t && (this.setData({
                integral: t
            }), this.data.integral && wx.setNavigationBarTitle({
                title: this.data.integral + "转账"
            }));
        } catch (a) {}
    },
    onReady: function() {},
    onShow: function() {
        this._getIntegral();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    _getIntegral: function() {
        var a = this, t = n.getNetAddresss("finance.point-page.index");
        n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    credit1: e.data.credit1,
                    need_password: e.data.need_password,
                    has_password: e.data.has_password,
                    rate: e.data.rate
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    transferidchange: function() {
        var a = this, t = n.getNetAddresss("member.member.memberInfo");
        t += "&uid=" + this.data.transfer_id, n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    memberInfo: e.data
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    transferidinp: function(a) {
        var t = a.detail.value;
        this.setData({
            transfer_id: t
        }), this.transferidchange();
    },
    transferpointinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "info_form.transfer_point": t
        });
    },
    remarkinp: function(a) {
        var t = a.detail.value;
        this.setData({
            remark: t
        });
    },
    payKeyboardComplete: function(a) {
        e.payKeyboardAsync.complete(a.detail);
    },
    getPayKeyboardPassword: function() {
        return this.setData({
            payKeyboardShow: !0
        }), new Promise(function(a, t) {
            e.payKeyboardAsync.addCompleteFn(function(t) {
                a(t);
            });
        });
    },
    payKeyboardClose: function() {
        this.setData({
            payKeyboardShow: !1
        });
    },
    confirm: function() {
        var e = this;
        return t(a.default.mark(function t() {
            var r, o;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (!(parseFloat(e.data.info_form.transfer_point) > parseFloat(e.data.credit1))) {
                        a.next = 3;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让".concat(e.data.integral, "不可大于您的").concat(e.data.integral),
                        duration: 1500
                    }), a.abrupt("return");

                  case 3:
                    if (!(null == e.data.transfer_id || e.data.transfer_id <= 0 || 0 == e.data.transfer_id.length)) {
                        a.next = 6;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让id不可为空",
                        duration: 1500
                    }), a.abrupt("return");

                  case 6:
                    if (!(null == e.data.info_form.transfer_point || e.data.info_form.transfer_point <= 0 || 0 == e.data.info_form.length)) {
                        a.next = 9;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让".concat(e.data.integral, "不可低于0"),
                        duration: 1500
                    }), a.abrupt("return");

                  case 9:
                    if (1 != e.data.need_password || 0 != e.data.has_password) {
                        a.next = 15;
                        break;
                    }
                    return a.next = 12, n.confirm("请先设置支付密码");

                  case 12:
                    return a.sent && wx.navigateTo({
                        url: "/packageA/member/set_balance_password/set_balance_password"
                    }), a.abrupt("return");

                  case 15:
                    if (r = n.getNetAddresss("finance.point-transfer.index"), r += "&recipient=" + e.data.transfer_id, 
                    r += "&transfer_point=" + e.data.info_form.transfer_point, 1 != e.data.need_password) {
                        a.next = 23;
                        break;
                    }
                    return a.next = 21, e.getPayKeyboardPassword();

                  case 21:
                    o = a.sent, r += "&password=" + o;

                  case 23:
                    e.data.remark && (r += "&remark=" + e.data.remark), n._getNetWork({
                        url: r,
                        success: function(a) {
                            var t = a.data;
                            1 == t.result ? wx.showToast({
                                title: t.msg,
                                icon: "none",
                                duration: 1500,
                                success: function() {
                                    setTimeout(function() {
                                        wx.navigateBack({
                                            delta: 1
                                        });
                                    }, 1500);
                                }
                            }) : wx.showToast({
                                icon: "none",
                                title: t.msg,
                                duration: 1500
                            });
                        },
                        fail: function(a) {
                            console.log(a);
                        }
                    });

                  case 25:
                  case "end":
                    return a.stop();
                }
            }, t);
        }))();
    }
});